473,468 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Binding Dropdownlist in Edit Template of datagrid

When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below

<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
Width="172px">
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>
Mar 13 '07 #1
2 7436
Victorious1 schrieb:
When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below

<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
Width="172px">
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>

Hi,

I think the properties DataValueField and DataTextField are used only
when the elements for the drop down list are retrieved dynamically (from
a lookup table or something like that). But it looks like you have
static values in your drop down list and only want to select the one
that is in the database. For this, you need to bind the property
SelectedValue, in your example:

<asp:DropDownList ID="DropDownListStatus" runat="server" SelectedValue
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>

Also, please note that you have a discrepancy between your text and your
values (In progress - Not appropriate; Not appropriate - Screening)

Hope this helps,

Cheers,

Roland

Mar 13 '07 #2
Thanks for pointing out the discrepancies. However, when I try to set the
selected value from HTML I get the following error message.

Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: The 'SelectedValue' property is set only by the
runtime. It cannot be declared.

Source Error:
Line 134: </ItemTemplate>
Line 135: <EditItemTemplate>
Line 136: <asp:DropDownList ID="DropDownListStatus" runat="server"
Line 137: SelectedValue = '<%# DataBinder.Eval(Container,
"DataItem.screen_status") %>;'
Line 138: DataValueField = '<%# DataBinder.Eval(Container,
"DataItem.screen_status") %>'
Source File: c:\inetpub\wwwroot\BIC_WEB_ACCESS\Screening.aspx Line: 136
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032

"Roland Dick" wrote:
Victorious1 schrieb:
When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below

<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
Width="172px">
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>


Hi,

I think the properties DataValueField and DataTextField are used only
when the elements for the drop down list are retrieved dynamically (from
a lookup table or something like that). But it looks like you have
static values in your drop down list and only want to select the one
that is in the database. For this, you need to bind the property
SelectedValue, in your example:

<asp:DropDownList ID="DropDownListStatus" runat="server" SelectedValue
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>

Also, please note that you have a discrepancy between your text and your
values (In progress - Not appropriate; Not appropriate - Screening)

Hope this helps,

Cheers,

Roland

Mar 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: ShadowsOfTheBeast | last post by:
hi all i am trying to bind data to my datagrid from a listbox which i think it should work but an error is coming up saying i have to bind to a datasource that implements the Inumerable or...
2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
0
by: Wayneb | last post by:
Hi I have a datagrid with autogenerates columns based upon a dataset I have constructed from the results of database query - pretty noddy stuff. When you click on Edit I remove the standard...
0
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
2
by: NewToDotNet | last post by:
Hi, I am very new to ASP.NET and web programming in general. I have one issue. I have a Datagrid object with Edit template. In one Datagrid row, I have 1 DropdownList, 1 textbox and 1 readonly...
1
by: Harold | last post by:
Hi all, having a little difficulty binding up a dropdownlist control in a datagrid column. I know I must be missing something Here are 2 methods. One is the DataGrid's ItemDataBound event to catch...
9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
2
by: bmayer | last post by:
I am using a detail view and binding it to a sql data source (at some point in the future it will be an object data source). I have seen the article "Working with Data is ASP.NET 2.0 ::...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.